<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *商品管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
$return=array();
$tabs=array(
	array('op'=>'edit','title'=>'修改销售价格'),
	array('op'=>'log','title'=>'操作日志'),
);
if($_RQ['op']=='edit'){
	$return=array();
	$return['item']=$this->plugin_setting('basic');
	$return['item']['excelurl']=SITEROOT.'/addons/jy_upprice/resource/upprice2.xlsx';
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>$tabs,
		'edit'=>array(
				array('type'=>'radio','title'=>'改销售价规则','name'=>'up2type','options'=>'up2types'),
				array('type'=>'unitstring','unit'=>'元','title'=>'按导入销售价加减N元','name'=>'up2jianfee','show'=>array('up2type'=>1)),
				array('type'=>'unitstring','unit'=>'%','title'=>'按导入销售价加减N%','name'=>'up2jianrate','show'=>array('up2type'=>2),'help'=>'例如填-5；表示减5%；'),
				array ('name' => 'excelurl','type' => 'copy','title' => 'XLSX示例文件下载'),
				array ('name' => 'excel','type' => 'upfile','title' => '上传XLSX','help'=>'商品标题匹配顺序：《系列》--《型号》--《标题关键词》；规格匹配：《规格1》《规格2》《规格3》（留空不匹配）'),
				array('type'=>'select2_line','name'=>'pcate','options'=>'pcates','title'=>'选择分类','help'=>'[温馨提示]：选择分类',
					'name2'=>'ccate','options2'=>'ccates','title2'=>'请选择二级分类',
					'name3'=>'scate','options3'=>'scates','title3'=>'请选择三级分类',
				),
				
		)
	);
	$groupspram=array('uniacid'=>$_SESSION['uniacid'],'parentid'=>0,'merchid'=>0,'mid'=>0);
	$return['pcates']=pdo_getall('jy_weishop_goods_group',$groupspram,array('title','id'),'id');
	foreach($return['pcates'] as &$pv){
		$pv['ccates']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'parentid'=>$pv['id']),array('title','id'),'id');
		foreach($pv['ccates'] as &$cv){
			$cv['scates']=pdo_getall('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'parentid'=>$cv['id']),array('title','id'),'id');
		}
	}
	$return['up2types']=array('按导入销售价修改','按导入销售价加减N元','按导入销售价加减%');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['excel']){
		exi('请上传XLSX','error');
	}
	if(!$postdata['pcate']){
		exi('商品分类不能为空','error');
	}
	if($postdata['up2type']==1 && !$postdata['up2jianfee']){
		exi('请输入销售价加减N元','error');
	}
	if($postdata['up2type']==2 && !$postdata['up2jianrate']){
		exi('请输入销售价加减N%','error');
	}
	$this->model('model')->daoru($postdata);
	exi('操作成功！');
}
if($_RQ['op']=='log'){
	$return['params']=array();
	$params=array('type'=>2,'uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['type']) && $_RQ['type']!=100){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=intval($_RQ['type']);
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:20;
	$list=pdo_getslice('jy_upprice_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['grouptitle']=pdo_getcolumn('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['pcate']),'title');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'id','title'=>'ID','type'=>'string'),
			array('name'=>'grouptitle','title'=>'商品分类','type'=>'string'),
			array('name'=>'type','title'=>'操作类型','type'=>'radio','options'=>'up2types'),
			array('name'=>'fee','title'=>'变动幅度','type'=>'string'),
			array('name'=>'createtime','title'=>'预约时间','type'=>'time'),
		)),
		'search'=>array(
			array('type'=>'radio','width'=>15,'name'=>'type','options'=>'up2types','title'=>'类型'),
		),
	);
	$return['up2types']=array('按导入销售价修改','按导入销售价加减N元','按导入销售价加减%');
	$return['htmls']=$htmls;	
	exi($return);
}